package com.huawei.M01.iterator.F06;

public class reverseNodeList {
    public NodeList reverseList(NodeList head) {
        // 使用递归进行反转
        if (head == null || head.next == null) {
            return head;
        }

        NodeList cur = reverseList(head.next);

        // 将当前结点与当前结点的下一个结点连接
        head.next.next = head;

        // 断掉正向关系
        head.next = null;

        // 执行到此即可返回当cur, 即递归后找到的尾结点
        return cur;
    }
}

class NodeList {
    int value;

    NodeList next = null;

    public NodeList(int value) {
        this.value = value;
    }
}